package game.source.shot;

import game.source.gui.shot.CallBackShotInterface;
import game.source.manager.ShowInterface;
import game.source.physics.PhysicsObjectInterface;
import game.source.ships.GameInterface;
import game.source.ships.Ship;
import game.source.shot.GuiShotInterface.Level;
import game.source.shot.GuiShotInterface.Shooter;
import game.source.sound.AudioBuffer;
import game.source.sound.WavePlayer;

import java.awt.Point;

/*Shot:
 *	Armazena as informações do tiro.
 */
public abstract class Shot implements CallBackShotInterface,PhysicsObjectInterface,ShowInterface{
	private Shooter 			shooter;
	private Level				level;
	private GuiShotInterface	gui;
	private GameInterface		game;
	private static AudioBuffer	buffer;
    private WavePlayer 			sound_Shot;
    static{
    	Shot.buffer = new AudioBuffer("/sounds/shot.wav");
    }
	public Shot(GuiShotInterface gui, Shooter shooter, Level level,GameInterface game,Point start,double vel){
		this.gui		= gui;
		this.shooter	= shooter;
		this.level		= level;
		this.game		= game;
		this.gui.setShot(this);
		Point tmp = new Point(start.x - this.gui.getWidth()/2,start.y);
		this.gui.setStartPosition(tmp);
		this.gui.setVel(vel);
		this.sound_Shot = new WavePlayer(Shot.buffer);
		this.sound_Shot.play();
	}
	
	@Override
	public Shooter getShooter(){
		return this.shooter;
	}
	
	public Level getLevel(){
		return this.level;
	}
	
	public GameInterface getGame(){
		return this.game;
	}
	
	@Override
	public int getX0() {
		return this.gui.getX0();
	}
	@Override
	public int getY0() {
		return this.gui.getY0();
	}
	@Override
	public int getWidth() {
		return this.gui.getWidth();
	}
	@Override
	public int getHeight() {
		return this.gui.getHeight();
	}
	@Override
	public byte getPixelAlpha(int x, int y) {
		return this.gui.getPixelAlpha(x, y);
	}	
	@Override
	public void show(long time){
		this.gui.show(time);
	}
	
	public void end(){
//		System.out.println("end");
		this.sound_Shot.end();
	}

	public abstract int getDamage();
	public abstract void action(Ship hit);
}
